home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / EXAMP6.SQL < prev    next >
Encoding:
Text File  |  1995-05-18  |  1.9 KB  |  57 lines

  1. rem 
  2. rem $Header: examp6.sql 7020100.1 94/09/28 16:39:51 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      examp6.sql - <one-line expansion of the name>
  7. Rem    DESCRIPTION
  8. Rem      <short description of component this file declares/defines>
  9. Rem    RETURNS
  10. Rem 
  11. Rem    NOTES
  12. Rem      <other useful comments, qualifications, etc.>
  13. Rem    MODIFIED   (MM/DD/YY)
  14. Rem     rvasired   05/12/92 -  Creation 
  15. /*
  16. ** This block accumulates 1000 units of part number 5469 from
  17. ** various storage bins.
  18. **
  19. ** Copyright (c) 1989,1992 by Oracle Corporation
  20. */
  21. DECLARE
  22.     CURSOR bin_cur(part_number NUMBER) IS SELECT amt_in_bin
  23.         FROM bins
  24.         WHERE part_num = part_number AND 
  25.             amt_in_bin > 0
  26.             ORDER BY bin_num
  27.             FOR UPDATE OF amt_in_bin;
  28.     bin_amt        bins.amt_in_bin%TYPE;
  29.     total_so_far    NUMBER(5) := 0;
  30.     amount_needed   CONSTANT NUMBER(5) := 1000;
  31.     bins_looked_at  NUMBER(3) := 0;
  32. BEGIN
  33.     OPEN bin_cur(5469);
  34.     WHILE total_so_far < amount_needed LOOP
  35.         FETCH bin_cur INTO bin_amt;
  36.         EXIT WHEN bin_cur%NOTFOUND;
  37.              /* If we exit, there's not enough to *
  38.               * satisfy the order.                */
  39.         bins_looked_at := bins_looked_at + 1;
  40.         IF total_so_far + bin_amt < amount_needed THEN
  41.             UPDATE bins SET amt_in_bin = 0
  42.                 WHERE CURRENT OF bin_cur;  
  43.                     -- take everything in the bin
  44.             total_so_far := total_so_far + bin_amt;
  45.         ELSE        -- we finally have enough
  46.             UPDATE bins SET amt_in_bin = amt_in_bin
  47.                 - (amount_needed - total_so_far)
  48.                 WHERE CURRENT OF bin_cur;
  49.             total_so_far := amount_needed;
  50.         END IF;
  51.     END LOOP;
  52.     CLOSE bin_cur;
  53.     INSERT INTO temp VALUES (NULL, bins_looked_at, '<- bins looked at');
  54.     COMMIT;
  55. END;
  56. /
  57.